class Solution
{
public:
    int numUniqueEmails(vector<string> &emails)
    {
        auto processName = [](string &s)
        {
            string result;
            int n = s.size();
            int i = 0;
            while (true)
            {
                if (s[i] == '+')
                {
                    while (s[i] != '@')
                    {
                        ++i;
                    }
                    break;
                }
                if (s[i] == '@')
                {
                    break;
                }
                if (s[i] != '.')
                {
                    result.push_back(s[i]);
                }
                ++i;
            }
            while (i < n)
            {
                result.push_back(s[i]);
                ++i;
            }
            return result;
        };

        unordered_set<string> names;
        for (string &email : emails)
        {
            names.insert(processName(email));
        }
        return names.size();
    }
};